<template>
	<view class="content">
			<view class="section-0">
					<view class="section-body">
						<view :class="`item ${curBoard === item.state ? 'item__on': ''}`" @click="setCurBoard(item)" v-for="item in board" :key="item.name">
							<view class="shape" v-if="item.right"></view>
							<view class="shape2" v-if="item.bottom"></view>
							<view class="top">{{item.name}}</view>
							<view class="bottom">{{analysis[item.type]}}</view>
						</view>
					</view>
				</view>
				<view class="section-1">
					<view class="form">
						<view class="form-item">
							<view class="label">项目名称</view>
							<view class="shape"></view>
							<view class="input">
								<u--input
									placeholderClass="input-placeholder"
									class="input-body"
									v-model="form.project_name"
								  ></u--input>
							</view>
						</view>
						<view class="actions">
							<view class="action" @click="handleResetForm()">
								<text>重</text>
								<text>置</text>
							</view>
							<view class="action search" @click="handleSearch()">
								<text>查</text>
								<text>询</text>
							</view>
						</view>
					</view>
					<view class="list">
						<view :class="`item ${expandList.indexOf(item.id) !== -1 ? 'item__expand' : ''}`"
							v-for="(item, index) in list" :key="item.id">
							<view class="parent">
								<view class="action" @click="expandChange(item.id)">
									<view class="iconfont icon-xiangyou1"></view>
								</view>
								<view class="name">
									{{index + 1}}.{{item.name}}
								</view>
								<view class="problem">
									<view class="count">{{item.count}}<text>人</text></view>
									<view class="problem-title">人员数量：</view>
								</view>
							</view>
							<view class="child" v-if="expandList.indexOf(item.id) !== -1">
								<view class="child-item" @click="go(item2.id)" v-for="(item2, idx) in item.children" :key="item2.id + idx">
									<view class="top">
										<view class="name">
											{{index + 1}}-{{idx + 1}}.{{item2.name}}
										</view>
										<view class="problem">
											<view class="count">{{item2.count}}<text>人</text></view>
											<view class="problem-title">人员数量：</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
		</view>
	</view>
</template>

<script>
	import {
		projectSumApi,
		companyPersonListApi
	} from '@/api/person.js';
	import { mapGetters, mapActions} from 'vuex';
	import formArea from '@/components/form_area/index.vue';
	export default {
		components: { formArea },
		data() {
			return {
				form: {
					project_name: ''
				},
				name: '',
				board: [
					{ name: '在建项目总数', count: 0, right: true, bottom: true, type: 'project_num' },
					{ name: '人员总数', count: 0, right: true,  bottom: true, type: 'people_num' },
					{ name: '业主人员总数', count: 0, bottom: true, type: 'owner_num' },
					{ name: '监理人员总数', count: 0, right: true, type: 'control_num' },
					{ name: '施工人员总数   ', count: 0, right: true, type: 'construction_num' },
					{ name: '分包人员总数', count: 0, type: 'subcontract_num' },
				],
				list:   [],
				expandList: [],
				analysis: {},
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption:{
					textNoMore: '-- 没有更多了 --'
				},
				pageSize:20,
				showStart: false,
				timeStamp: '',
				curBoard: 1,
			};
		},
		methods: {
			setCurBoard(item) {
				debugger
				if (!item.state) return;
				this.curBoard = item.state;
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
			showDate(type) {
				this.timeType = type;
				this.showStart = true;
			},
			closeDate(type) {
				this.timeType = '';
				this.showStart = false;
			},
			async expandChange(id, project_id) {
				const idx = this.expandList.indexOf(id);
				if (idx !== -1) {
					this.expandList.splice(idx, 1);
				} else {
					this.expandList.push(id);
				}
				if (project_id) {
					if (!this.list[id.split('-')[0]].children[id.split('-')[1]].children) {
						this.fetchInfo(id, project_id)
					}
				}
			},
			async fetchInfo(id, project_id) {
				uni.showLoading({title: '加载中...'});
				const { data } = await companyPersonListApi({id: project_id});
				if (data.code === 1) {
					let dep = JSON.parse(JSON.stringify(this.list));
					dep[id.split('-')[0]].children[id.split('-')[1]].children = data.data;
					this.list = dep;
				}
				uni.hideLoading();
			},
			go(params) {
				uni.navigateTo({
					url: '/pages/statistics/group/people/import/index?pro_id=' + params
				})
			},
			async projectAnalysis() {
				uni.showLoading({title: '加载中...'});
				const { data } = await projectSumApi();
				uni.hideLoading();
				if (data.code === 1) {
					this.analysis = data.data;
				}
			},
			/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			async selectLIst() {
				const {data} =  await companyPersonListApi({
					...this.form,
				});
				if (data.code === 1 || data.code === 200) {
					this.list = data.data;
				}
			},
			handleResetForm(){
				console.log(this.form);
				this.form.project_name=''
				this.handleSearch()
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
			async handleSearch(page) {
				uni.showLoading({title: '加载中...'});
				const j = await companyPersonListApi({
					...this.form,
				});
				this.list=j.data.data
				if(j.data.code = 1) {
					uni.hideLoading();
				}
				
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
		},
		onReady() {
			this.timeStamp = (new Date()).valueOf();
			this.projectAnalysis();
			this.selectLIst();
			// this.fetchData();
		},
		onNavigationBarButtonTap(res) {
			uni.navigateTo({
				url: '/pages/statistics/safety/team/blacklist/index?type=team'
			})
		},
	}
</script>

<style lang="scss" scoped>
	.custom-empty{
		position: static;
	}
	.content{
		background-color: #fff;
	}
	.section-1{
		position: relative;
		top: -50rpx;
		z-index: 10;
		background-color: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		overflow: hidden;
		.form{
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-item{
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();
				.label{
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.shape{
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input{
					height: 100%;
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.time-body{
						height: 48rpx;
						width: 45%;
						float: left;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
						text-align: center;
						line-height: 48rpx;
					}
					.time-split{
						float: left;
						width: 10%;
						text-align: center;
						color: #1534ce;
					}
					.input-body{
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0!important;
						border: none;
						padding-left: 30rpx!important;
						padding-right: 30rpx!important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
					}
					.input-placeholder{
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.5);
					}
				}	
			}
		}
		
		.list{
			
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			border-top: 2rpx solid #d8e4f2;
		
			.item {
				width: 100%;
				border-bottom: solid 2rpx #f2f2f0;
		
				.parent {
					width: 100%;
					@include clear();
					.name {					
						width: 380rpx;
						line-height: 30rpx;
						padding: 26rpx 0;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 2rpx;
						color: #3b3c40;
						float: left;
					}
					.problem{
						width: 200rpx;
						height: 46rpx;
						line-height: 46rpx;
						font-size: 16rpx;
						color: #3b3c40;
						float: right;
						.problem-title{
							font-size: 16rpx;
							color: #3b3c40;
							float: right;
							height: 46rpx;
							line-height: 46rpx;
							margin-top: 18rpx;
						}
						.count {
							float: right;
							min-width: 80rpx;
							height: 46rpx;
							margin-top: 18rpx;
							border-radius: 28rpx;
							line-height: 46rpx;
							text-align: center;
							font-size: 23rpx;
							font-weight: bold;
							color: #395cf5;
							background: #ffde00;
							text {
								font-size: 16rpx;
							}
						}
					}
					
		
					.action {
						float: left;
						width: 32rpx;
						margin-right: 18rpx;
						line-height: 82rpx;
						text-align: center;
						color: #3b3c40;
		
						.iconfont {
							font-size: 32rpx;
							transition: 0.2s ease;
							transform: rotate(90deg);
						}
		
					}
				}
				.child {
					width: 750rpx;
					margin-left: - 40rpx;
					background: #f2f2fa;
		
					.child-item {
						box-sizing: border-box;
						padding-left: 50rpx;
						width: 100%;
						border-bottom: 2rpx solid #e3e8f5;
						box-sizing: border-box;
						padding-right: 40rpx;
						@include clear();
						&:last-child {
							border-bottom: none;
						}
						
						
						.top {
							width: 100%;
							overflow: hidden;
							box-sizing: border-box;
							padding-left: 40rpx;
		
							.name {
								float: left;
								width: calc(100% - 290rpx);
								box-sizing: border-box;
								padding: 26rpx 0;
								font-size: 26rpx;
								color: #3b3c40;
								font-size: 26rpx;
							}
							.problem{
								width: 200rpx;
								height: 46rpx;
								line-height: 46rpx;
								font-size: 16rpx;
								color: #3b3c40;
								float: right;
								.count {
									float: right;
									min-width: 46rpx;
									height: 46rpx;
									margin-top: 18rpx;
									border-radius: 28rpx;
									line-height: 46rpx;
									text-align: center;
									font-size: 16rpx;
									color: #3b3c40;
									text {
										font-size: 16rpx;
									}
								}
								.problem-title{
									font-size: 16rpx;
									color: #3b3c40;
									float: right;
									height: 46rpx;
									line-height: 46rpx;
									margin-top: 18rpx;
								}
							}
		
							.action {
								width: 32rpx;
								line-height: 82rpx;
								float: left;
								text-align: center;
								color: #7f98ae;
								margin-right: 18rpx;
								.iconfont {
									font-size: 32rpx;
									transition: 0.2s ease;
									transform: rotate(90deg);
								}
							}
						}
					}
				}
				
				.grad{
					width: 100%;
					background: #d9d9e2;
					.grad-item{
						width: 100%;
						border-bottom: 2rpx solid #e3e8f5;
						
						&:last-child {
							border-bottom: none;
						}
						
						.grad-top {
							width: 100%;
							overflow: hidden;
							box-sizing: border-box;
							padding-left: 40rpx;
							.name {
								float: left;
								width: calc(100% - 40rpx);
								padding: 26rpx 0;
								padding-bottom: 10rpx;
								font-size: 26rpx;
								color: #3b3c40;
								padding-left: 50rpx;
								box-sizing: border-box;
							}
							.desc{
								float: left;
								width: calc(100% - 40rpx);
								font-size: 16rpx;
								color: #9b9b9b;
								box-sizing: border-box;
								padding-left: 50rpx;
								padding-bottom: 26rpx;
								text{
									min-width: 300rpx;
									margin-right: 30rpx;
									display: inline-block;
								}
							}
						}
					}
				}
				.action__active{
					.iconfont{
						transform: rotate(-90deg)!important;
					}
				}
			}
		
			.item__expand {
					.parent {
						.action {
							.iconfont {
								transform: rotate(-90deg);
							}
						}
					}
			
					.child {
						box-shadow: 0rpx 10rpx 10rpx 0rpx rgba(0, 0, 0, 0.05) inset;
					}
				}
			
		}
		.form{
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-item{
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();
				.label{
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.shape{
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input{
					height: 100%;
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.time-body{
						height: 48rpx;
						width: 45%;
						float: left;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
						text-align: center;
						line-height: 48rpx;
					}
					.time-split{
						float: left;
						width: 10%;
						text-align: center;
						color: #1534ce;
					}
					.input-body{
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0!important;
						border: none;
						padding-left: 30rpx!important;
						padding-right: 30rpx!important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
					}
					.input-placeholder{
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.5);
					}
				}	
			}
			.actions{
				width: 100%;
				height: 50rpx;
				margin-top: 29rpx;
				padding-bottom: 40rpx;
				display: flex;
				justify-content: space-between;
				.action{
					width: 288rpx;
					height: 48rpx;
					background-color: #395cf5;
					border-radius: 20rpx;
					text-align: center;
					line-height: 48rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					line-height: 48rpx;
					color: #ffffff;
					text{
						&:first-child{
							margin-right: 20rpx;
						}
					}
				}
				.search{
					background-color: #1534ce;
				}
			}
		}
	}
	.section-0{
		width: 100%;
		background-color: #2e5efe;
		.section-body{
			width: 100%;
			padding-left: 40rpx;
			padding-right: 40rpx;
			padding-bottom: 50rpx;
			padding-top: 20rpx;
			background-color: #1534ce;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			overflow: hidden;
			box-sizing: border-box;
			.item{
				width: 33.33%;
				float: left;
				display: flex;
				flex-wrap: wrap;
				align-content: space-between;
				height: 100rpx;
				position: relative;
				padding-top: 20rpx;
				padding-bottom: 20rpx;
				.shape{
					width: 4rpx;
					height: 84rpx;
					background-image: linear-gradient(rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%,);
					position: absolute;
					right: 0;
					top: 28rpx;
				}
				.shape2{
					height: 4rpx;
					width: 172rpx;
					background-image: linear-gradient(90deg, rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%,);
					position: absolute;					
					left: 0;
					right: 0;
					margin: 0 auto;
					bottom: -2rpx;
				}
				.top{
					width: 100%;
					text-align: center;
					font-size: 16rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #95c4fa;
				}
				.bottom{
					width: 100%;
					text-align: center;
					font-size: 58rpx;
					font-weight: bold;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #ffde00;
				}
			}
			.item__on{
				.top{
					text-shadow: 8rpx 8rpx 8rpx rgba(0, 0, 0, 0.3);
				}
				.bottom{
					text-shadow: 8rpx 8rpx 8rpx rgba(0, 0, 0, 0.3);
				}
			}
		}
	}
</style>
